﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Antlr.Runtime;

namespace PSLib.Parsing.Common
{
    public class RecognizedToken
    {
        public RecognizedToken(IToken token, RecognizedTokenType type)
        {
            if (token == null) throw new ArgumentNullException("token");
            this.NativeToken = token;
            this.Type = type;
        }

        public static bool operator ==(RecognizedToken x, string y)
        {
            if (Object.Equals(x, null) && Object.Equals(y, null)) return true;
            if (Object.Equals(x, null) || Object.Equals(y, null)) return false;
            return x.NativeToken.Text == y;
        }

        public static bool operator !=(RecognizedToken x, string y)
        {
            return !(x == y);
        }

        public static bool operator ==(RecognizedToken x, RecognizedTokenType y)
        {
            if (Object.Equals(x, null) || Object.Equals(y, null)) return false;
            return x.Type == y;
        }

        public static bool operator !=(RecognizedToken x, RecognizedTokenType y)
        {
            return !(x == y);
        }

        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        public override int GetHashCode()
        {
            return this.NativeToken.GetHashCode() + this.Type.GetHashCode();
        }

        public override string ToString()
        {
            return string.Format("Token: {0}<{1}>",this.NativeToken,this.Type);
        }

        public IToken NativeToken { get; private set; }
        public RecognizedTokenType Type { get; private set; }
    }
}
